package com.kevis.zhunblog.admin.controller;

import com.kevis.zhunblog.core.entities.RoleEntity;
import com.kevis.zhunblog.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//import com.kevis.zhunblog.service.test.UserService;

//@Repository
@RestController
@RequestMapping("/test")
public class TestController {
//    @Autowired
//    private UserService service;

    @Autowired
    private RoleService roleService;

    @GetMapping("/test1")
    public String test1(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        TestBo bo = service.getUser();
//        TestVo vo = new TestVo();
//        vo.setId(bo.getId());
//        vo.setName(bo.getName());
//        System.out.println("controller...." + vo.toString());
        List<RoleEntity> roleServiceAll = roleService.list();
        for (RoleEntity roleEntity : roleServiceAll) {
            System.out.println("web:" + roleEntity.toString());
        }
        request.setAttribute("bb","cc");
        request.getRequestDispatcher("/test/test2").forward(request, response);

        return "<h3>你好，这个是我的博客哦~</h3>";
    }

    @GetMapping("/test2")
    public String test2(HttpServletRequest request, HttpServletResponse response) {
        System.out.println(request.getAttribute("bb"));
        return "<h3>你好，这个是我的博客哦11111~</h3>";
    }

    @GetMapping("/test")
    public ModelAndView test(){
        ModelAndView mav = new ModelAndView();
        mav.setViewName("test");
        return mav;
    }

    @GetMapping("/testerror")
    public String testerror(){
        throw new RuntimeException("aiyou");
    }
}
